package cn.edu.ctbu.test.controller;

import cn.edu.ctbu.test.domain.Student;
import cn.edu.ctbu.test.service.StudentService;
import cn.edu.ctbu.test.util.PageHelperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class StudentController {
    @Autowired
    StudentService studentService;

//    @RequestMapping("")
//    public String toStudent(){
//        return "student/student"; // 返回页面
//    }
//
//    @ResponseBody // 只返回数据
//    @RequestMapping("list")
//    public IPage<Student> getCourseAndScore(Integer size, Integer page, String condition){
//        PageHelperUtil pageHelperUtil = new PageHelperUtil();
//        IPage<Student> studentIPage = studentService.findAll();
//        return studentIPage;
//        return studentList; // 返回数据
//    }




//    @RequestMapping("selectByName")
//    public String getByName(String name){
//        name = "吴";
//        List<Student> byName = studentService.findByName(name);
//        return "student/student";
//    }

    @RequestMapping("/student/student")
    public String List(HttpServletRequest httprequest, Model model)
    {
        HttpSession session=httprequest.getSession();

        if(session.getAttribute("userid")==null){
            //未登录，需要登录
            return "redirect:index";
        }


        List<Student> students=studentService.findAll();

        model.addAttribute("data",students);

        return "student/student";
    }


}
